﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FlickrSample.SL.Infrastructure.Flickr.Commands;
using FlickrSample.SL.Infrastructure.Flickr.Entities;
using FlickrSample.SL.Infrastructure.Flickr.Parser;
using FlickrSample.SL.Infrastructure.Repo.Flickr;

namespace FlickrSample.SL.Infrastructure.Repo.Search.Online
{
    public class SearchRepo : ISearchRepo
    {
        private IFlickrRepo flickrRepo;

        public SearchRepo()
        {
            flickrRepo = ServiceLocator.FlickrRepo;
        }

        public void FindUserByEmail(string emailAddress, Action<FlickrUser> callback)
        {
            var command = new flickr_people_findByEmail(emailAddress);
            flickrRepo.ExecuteCommand(command, result =>
            {
                if (!string.IsNullOrEmpty(result))
                {
                    var user = UserParser.ParseSimple(result);
                    callback(user);
                }
                else
                {
                    callback(null);
                }

            });

        }

        public void FindUserByUserName(string userName, Action<FlickrUser> callback)
        {
            var command = new flickr_people_findByUsername(userName);
            flickrRepo.ExecuteCommand(command, result =>
            {
                if (!string.IsNullOrEmpty(result))
                {
                    var user = UserParser.ParseSimple(result);
                    callback(user);
                }
                else
                {
                    callback(null);
                }

            });
        }
    }
}
